using Senparc.Weixin.Helpers;
using Senparc.Weixin.HttpUtility;
using System;
using System.IO;
namespace Senparc.Weixin.MP.AdvancedAPIs.MerChant
{
	public static class PictureApi
	{
		public static PictureResult UploadImg(string accessToken, string fileName)
		{
			string text = "https://api.weixin.qq.com/merchant/common/upload_img?access_token={0}&filename={1}";
			string url = string.IsNullOrEmpty(accessToken) ? text : string.Format(text, accessToken, fileName);
			PictureResult result = new PictureResult();
			using (FileStream fileStream = FileHelper.GetFileStream(fileName))
			{
				string returnText = RequestUtility.HttpPost(url, null, fileStream, null, null, null, 10000, false);
				result = Post.GetResult<PictureResult>(returnText);
			}
			return result;
		}
	}
}
